import {Injectable} from '@angular/core';
import {HttpClientService} from '../../shared/services/http-client.service';
import {AppContextService} from '../../shared/services/app-context.service';
import {EntityService, enumAction} from '../../shared/services/entity.service';
import {StorageService} from '../../shared/services/storage.service';
import {RolePageConfig} from '../config/role.config';
import {RoleAddEditComponent} from '../component/role-add-edit.component';
import {PDialog} from '../../shared/model/share.model';
import {Role} from '../domain/role';

@Injectable()
export class RoleService extends EntityService {
  test = 'RoleService';
  constructor(
    private http: HttpClientService,
    private app: AppContextService,
    private storage: StorageService
  ) {
    super( http, app, storage );
    this.pageData = RolePageConfig;
    this.dialog = {
      add: RoleAddEditComponent,
      edit: RoleAddEditComponent
    };
    this.dialogData = {
      add: new PDialog()
    };
  }
  showAddDialog(item) {
    if (!item) {
      item = new Role();
      item.enabled = true;
    }
    super.showAddDialog(item);
  }
  // showAddDialog(item?) {
  //
  //   const addDialog = this.pageData.dialog.add;
  //   this.app.showDialog({
  //     header: addDialog.header,
  //     width: addDialog.width,
  //     yes: (res) => {
  //       console.log(res);
  //     }}, this, this.dialog.add, item);
  // }
  add(item?) {
    const addDialog = this.pageData.dialog.add;
    this.app.showDialog({
      header: addDialog.header,
      width: addDialog.width,
      yes: (res) => {
        console.log(res);
      }}, this, this.dialog.add, item);
  }
  edit(item?) {
    console.log(item);
    const addDialog = this.pageData.dialog.edit;
    this.app.showDialog({
      header: addDialog.header,
      width: addDialog.width,
      yes: (data) => {
        this.http.post(`${this.urlController}`, data)
          .do(res => {
            if (res.success) {

            }
          });
      }}, this, this.dialog.add, item);
  }
}
